package com.webshop.DataDao;

import com.webshop.JavaBean.Goods;
import com.webshop.JavaBean.Picture;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

public class Picture_uploadDao {
    QueryRunner q=new QueryRunner(DataSourceUtils.getDataSource());

    /**
     * 上传picture图片
     * @param picture
     * @throws Exception
     */
    public void upload(Picture picture)throws Exception{
        String sql ="insert into picture (path,goodsID,isMain,goodsAttrID) values(?,?,?,?)";
        Object[] parm = {picture.getPath(),picture.getGoodsID(),picture.getIsMain(),picture.getGoodsAttrID()};
        q.update(sql, parm);
    }
    /**
     * 上传图片
     * @param goods
     * @throws Exception
     */
    public void insertgoods(Goods goods)throws Exception{
        String sql="insert into goods (productName,isHot,owner,mainPic,state,createTime,category" +
                ",description,maxprice,minprice) values(?,?,?,?,?,?,?,?,?,?)";
        Object[] p={goods.getProductName(),goods.getIsHot(),goods.getOwner(),goods.getMainPic(),goods.getState()
                ,goods.getCreateTime(),goods.getCategory(),goods.getDescription(),goods.getMaxprice(),goods.getMinprice()};
        q.update(sql,p);
    }
   public int selectpic(String pic)throws Exception{
        String sql="select * from goods where mainPic = ?";
        Goods goods=new Goods();
       goods= q.query(sql,new BeanHandler<>(Goods.class),pic);
       return goods.getID();
   }
}
